package com.deer.wms.system.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.deer.wms.project.root.util.RedisUtil;
import com.deer.wms.system.manage.dao.CarrierMapper;
import com.deer.wms.system.manage.model.carrier.Carrier;
import com.deer.wms.system.manage.model.carrier.CarrierCriteria;
import com.deer.wms.system.manage.model.carrier.CarrierDto;
import com.deer.wms.system.manage.service.CarrierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by guo on 2019/11/13.
 */
@Service
@Transactional
public class CarrierServiceImpl extends ServiceImpl<CarrierMapper, Carrier> implements CarrierService {

    @Autowired
    private CarrierMapper carrierMapper;

    @Autowired
    private RedisUtil redisUtil;

    @Override
    public List<CarrierDto> findList(CarrierCriteria criteria) {
        return carrierMapper.findList(criteria);
    }

    public List<Carrier> findByCode(String carrierCode) {
        return carrierMapper.findByCode(carrierCode);
    }

    public List<Carrier> findByName(String carrierCode) {
        return carrierMapper.findByName(carrierCode);
    }

    @Override
    public Carrier findBy(String field, String value) {
        QueryWrapper<Carrier> qw = new QueryWrapper<>();
        return getOne(qw.eq(field, value));
    }

    @Override
    public boolean save(Carrier carrier){
        super.save(carrier);
        redisUtil.remove("allCarrier");
        return true;
    }

    public void deleteById(Integer carrierId){
        super.removeById(carrierId);
        redisUtil.remove("allCarrier");
    }

    public void update(Carrier carrier){
        super.updateById(carrier);
        redisUtil.remove("allCarrier");
    }
}
